package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.entity.TMemberLevel;
import com.quwan.manager.service.MemberLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author laozhang
 * @date 2021/9/25 11:47
 */
@Api(tags = "后台用户等级管理接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/memberLevel")
public class MemberLevelController  extends BaseController {

    private final MemberLevelService memberLevelService;

    @ApiOperation(value = "用户等级列表",notes = "<span style=\"color:red\">注意参数是否必填</span>",httpMethod = "POST")
    @PostMapping("memberLevelList")
    public ApiResult<List<TMemberLevel>> memberLevelList() {
        List<TMemberLevel> res = memberLevelService.getMemberLevelList();
        return ApiResult.success(res);
    }

    @PostMapping("updateMemberLevel")
    @ApiOperation("用户等级修改")
    public ApiResult updateMemberLevel(HttpServletRequest request, TMemberLevel memberLevel) {
        //TokenInfo tokenInfo = getTokenInfo(request);
        boolean success = memberLevelService.updateMemberLevel(memberLevel);
        if (success) return ApiResult.success();
        else return ApiResult.failed();
    }

    @PostMapping("addMemberLevel")
    @ApiOperation("用户等级添加")
    public ApiResult addMemberLevel(TMemberLevel memberLevel) {
        boolean success = memberLevelService.addMemberLevel(memberLevel);
        if (success) return ApiResult.success();
        else return ApiResult.failed();
    }

    @PostMapping("delCateTag")
    @ApiOperation("用户等级删除")
    public ApiResult delCateTag(@ApiParam("id") @RequestParam(required = true) Integer id) {

        boolean success = memberLevelService.delMemberLevel(id);
        if (success) return ApiResult.success();
        else return ApiResult.failed();
    }
}
